package com.hotel.controller;

import com.hotel.domain.Food;
import com.hotel.service.FoodService;
import com.hotel.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author shenlei
 * @describ
 * @create 2020-12-08 21:13
 */
@RestController
@RequestMapping("/admin")
public class FoodController {

    @Autowired
    FoodService foodService;

    //查询订单
    @GetMapping("/Listfood")
    public JsonData findAllFood(){
        List<Food> foods = foodService.findAllFood();
        return foods==null ?JsonData.buildError("查询失败！") : JsonData.buildSucess(foods);


    }

    //保存订单
    @PostMapping("/savefood")
    public void saveFoodOrder(){
       // food.setOrstartime(new Date());
        Food food = new Food();
        food.setOrstartime(new Date());

        //获取当前时间
        long currentTime = System.currentTimeMillis() ;
        //在这个基础上加上60分钟：
        currentTime +=60*60*1000;
        //格式化时间，获取到的就是当前时间半个小时之后的时间
        Date endTime=new Date(currentTime);


        food.setOrendtime(endTime);
        food.setOrderId(UUID.randomUUID().toString());
        food.setFoodName("辣椒");
        food.setFoodPrice(9);
        food.setFoodNum(1);
        food.setOrderName("ggg");
        foodService.saveFoodOrder(food);

    }




}
